# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reverseKGroup(self, head: ListNode, k: int) -> ListNode:
        if k==1:
            return head
        stack = []
        root = ListNode(0)
        cur = root
        while head:
            stack.append(head.val)
            head = head.next
        for i in range(Math.floor(len(stack)/k)):

            for j in range(k,0,-1):
                cur.next = ListNode(stack[j-1])
                cur = cur.next
                del stack[j-1]
        return root.next
        
            
        